package com.sun.controllers.users;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.util.SaResult;
import com.sun.dto.PagedList;
import com.sun.dto.users.UserSearchDto;
import com.sun.entity.users.User;
import com.sun.services.users.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * MP自动填充Handler
 *
 * @Author sun
 * @CreateTime 2025/9/3 00:48
 */
/**
 * 用户控制器，处理用户相关的HTTP请求
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @PostMapping("/createUser")
    SaResult createUser(@RequestBody User user) {
        return userService.createUser(user);
    }

    @PostMapping("/deleteUser")
    SaResult DeleteUser(@RequestBody List<Long> ids) {
        if (ids == null || ids.isEmpty()) {
            return SaResult.error("用户ID列表不能为空");
        }
        return userService.DeleteUser(ids);
    }
    @GetMapping("/getUserList")
    @SaIgnore
    SaResult getUserList(UserSearchDto searchDto) {
        List<User> userList = userService.getUserList(searchDto);
        return SaResult.data(userList);
    }
    @GetMapping("/getUserPageList")
    @SaIgnore
    SaResult getUserPageList( UserSearchDto searchDto) {
        PagedList<User> userPageList = userService.getUserPageList(searchDto);
        return SaResult.data(userPageList);
    }
    @PostMapping("/updateUser")
    SaResult updateUser(@RequestBody User user) {
        return userService.UpdateUser(user);
    }
}
